<template>
  <div class="JobList">
    <Header />
    <div class="image">
      <div class="image-wrap">
        <img src="../assets/image/fast-reg.png" alt="" />
        <div></div>
      </div>
    </div>

    <!-- 搜索star -->
    <div class="Search">
      <div class="search-wrap">
        <input
          class="search-ipt"
          type="search"
          v-model.trim="jobName"
          placeholder="搜索职位、公司"
          @input="SerachChange"
        />
        <button class="search-btn" @click="getSearchJob">搜索</button>
      </div>
      <div class="search-hidden" v-if="isSearchList">
        <div
          class="search-hidden-list"
          v-for="(item, index) in searchData"
          :key="index"
        >
          {{ item.jobName }}
        </div>
      </div>
    </div>
    <!-- 搜索end -->

    <!-- 搜索出来的职位列表star -->
    <div class="searchJobList" v-if="isSearchJobBox === true">
      <div class="Position" id="NewJobBox">
        <div
          class="Position-box"
          v-for="(item, index) in searchJobList"
          :key="index"
          @click="handleDetails(item, index)"
        >
          <div class="Position-content-top">
            <p class="Position-name">{{ item.jobName }}</p>
            <!-- <div class="guide-app-download-icon"></div> -->
            <p class="Position-price">{{ item.salaryDesc }}</p>
          </div>
          <p class="Position-content-center">
            {{ item.cityName }}
            <span class="vline"></span>
            {{ item.jobExperience }}
            <span class="vline"></span>
            {{ item.jobDegree }}
          </p>
          <div class="Position-content-bottom">
            <p><img :src="item.brandLogo" alt="" /></p>
            <a href="###" class="Position-content-bottom-info">
              <span class="name">{{ item.brandName }}</span>
              <span class="type">{{ item.brandIndustry }}</span>
              <span class="vline"></span>
              <span class="level">已上市</span>
            </a>
          </div>
        </div>
      </div>
      <button class="position-btn" @click="NewJobListClick">查看更多</button>
    </div>
    <!-- 搜索出来的职位列表end -->
    <div class="newJobList" v-if="isSearchJobBox === false">
      <p class="position-text">
        <!-- <span></span>
        最新发布职位
        <span></span> -->
      </p>
      <NewJobList />
    </div>

    <BottomNav />
  </div>
</template>

<script>
import Header from '../components/Header/index'
import Search from '../components/Search/Search'
import NewJobList from '../components/NewJobList/index'
import BottomNav from '../components/BottomNav/index'
export default {
  name: 'jobList',
  components: { Header, Search, NewJobList, BottomNav },
  data() {
    return {
      isSearchJobBox: false,
      jobName: '',
      searchData: [],
      isSearchList: false,
      searchJobList: [],
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getSearchList()
  },
  mounted() {},
  methods: {
    // 进入页面时搜索框隐藏框的内容置空
    getSearchList() {
      // this.searchData = []
      console.log(this.$route.params)
      if (this.$route.params.jobName) {
        // 显示搜索职位列表盒子
        this.isSearchJobBox = true
        // 关闭隐藏搜索列表
        this.isSearchList = false
        this.$request
          .post('/api/api/JobInfo/SelectMore', {
            jobName: this.$route.params.jobName,
          })
          .then((res) => {
            // console.log(res)
            this.searchJobList = res.data
          })
      }
    },
    // 点击获取搜索框焦点
    // SearchIpt() {
    //   this.isSearchList = !this.isSearchList
    // },
    // 搜索框的值改变时
    SerachChange() {
      // console.log(this.jobName)
      const data = {
        jobName: this.jobName,
      }
      if (this.jobName === '') {
        // 隐藏搜索职位列表盒子
        this.isSearchJobBox = false
        // 关闭隐藏搜索列表
        this.isSearchList = false
      } else {
        // 显示搜索职位列表盒子
        this.isSearchJobBox = true
        // 关闭隐藏搜索列表
        this.isSearchList = false
        this.$request.post('/api/api/JobInfo/SelectMore', data).then((res) => {
          // console.log(res)
          this.searchJobList = res.data
        })
      }
    },
    // 点击搜索按钮时
    getSearchJob() {
      // const data = {
      //   jobName: this.jobName,
      // }
      // // 显示搜索职位列表盒子
      // this.isSearchJobBox = true
      // // 关闭隐藏搜索列表
      // this.isSearchList = false
      // if (this.jobName === '') {
      //   // 隐藏搜索职位列表盒子
      //   this.isSearchJobBox = false
      //   // 关闭隐藏搜索列表
      //   this.isSearchList = false
      // } else {
      //   // 显示搜索职位列表盒子
      //   this.isSearchJobBox = true
      //   // // 关闭隐藏搜索列表
      //   // this.isSearchList = false
      //   this.$request.post('/api/api/JobInfo/SelectMore', data).then((res) => {
      //     // console.log(res)
      //     this.searchJobList = res.data
      //   })
      // }
    },

    // 查看更多按钮
    NewJobListClick() {
      var NewJobBox = document.getElementById('NewJobBox')
      var NewJobHeight = NewJobBox.clientHeight
      if (NewJobHeight <= 2190) {
        if (this.jobList.length % 9 !== 0) {
          NewJobBox.style.height = NewJobHeight + 146 + 'px'
        } else {
          NewJobBox.style.height = NewJobHeight + 438 + 'px'
        }
      }
      if (NewJobHeight > 2628) {
        NewJobBox.style.height = '2920px'
      }
      // console.log(NewJobHeight);
    },
    // 点击职位进入该职位的详情页并传递该职位的信息数据
    handleDetails(item, index) {
      // console.log(item,index);
      // console.log(item.encryptJobId);
      sessionStorage.setItem('jobDetail', JSON.stringify(item))
      let routeData = this.$router.resolve({
        path: '/positiondetails',
      })
      window.open(routeData.href, '_blank')
    },
    //
    // getJobList() {
    //   this.$request.get('/api/api/JobInfo/GetInfo').then((res) => {
    //     console.log(res)
    //     this.jobList = res.data.reverse()
    //   })
    // },
  },
}
</script>
<style scoped>
.JobList {
  width: 100%;
  height: 100%;
  background-color: #f6f6f8;
  /* padding-bottom: 100px; */
}
.image {
  width: 100%;
  height: 120px;
  background-color: #5dd5cb;
}
.image-wrap {
  width: 1084px;
  margin: auto;
}
.image-wrap img {
  width: 354px;
  height: 120px;
}

.Search {
  width: 100%;
  height: 130px;
  margin-top: 20px;
}
.search-wrap {
  width: 800px;
  height: 50px;
  margin: auto;
}
.search-ipt {
  width: 640px;
  height: 50px;
  border: none;
  padding-left: 10px;
  font-size: 16px;
  color: #414a60;
  outline: none;
  box-shadow: 0 0 6px 0 rgb(0 0 0 / 13%);
}
.search-btn {
  width: 140px;
  height: 54px;
  padding-bottom: 4px;
  background-color: #55cbc4;
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
.search-btn:hover {
  background-color: #5dd5cb;
}
.search-hidden {
  width: 640px;
  height: 200px;
  background-color: #fff;
  position: relative;
  top: 4px;
  left: 366px;
  overflow: scroll;
}
.search-hidden-list {
  /* width: 652px; */
  height: 30px;
  line-height: 30px;
  padding-left: 10px;
  margin: 10px 0;
  cursor: pointer;
}
.search-hidden-list:hover {
  background-color: #f0f9eb;
}

.searchJobList {
  width: 1200px;
  height: 400px;
  margin: auto;
  margin-bottom: 200px;
}
.newJobList {
  width: 1200px;
  margin: auto;
  background-color: #f6f6f8;
}
.position-text {
  text-align: center;
  font-size: 24px;
  color: #414a60;
  margin: 30px;
  display: block;
  /* margin-top: 150px; */
}
/* .position-text span {
  display: inline-block;
  width: 50px;
  height: 2px;
  vertical-align: 8px;
  background-color: #414a60;
} */

.Position {
  width: 1184px;
  height: 438px;
  overflow: hidden;
  margin: auto;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-content: flex-start;
  flex-wrap: wrap;
  align-items: center;
}
.Position-box {
  width: 344px;
  height: 90px;
  background-color: #fff;
  margin-right: 16px;
  margin-bottom: 16px;
  padding: 20px;
  cursor: pointer;
}
.Position-box:hover {
  box-shadow: 2px 2px 20px #c7c5c5;
  transform: scale(1.01);
}
.Position-box:hover .Position-name {
  color: #55cbc4;
}
.Position > .Position-box:nth-child(3n) {
  margin-right: -10px;
}
.Position-content-top {
  display: flex;
  width: 100%;
  align-items: center;
}
.Position-name {
  position: relative;
  max-width: 200px;
  font-size: 15px;
  color: #414a60;
  margin-right: 8px;
  line-height: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* .guide-app-download-icon{
  display: inline-flex;
    width: 15px;
    height: 13px;
    background: url(../images/guide-add-download-icon.png) no-repeat;
    background-size: 100% 100%;
} */
.Position-price {
  font-size: 15px;
  color: #fd7240;
  line-height: normal;
  flex: 1;
  text-align: right;
  max-width: none;
}
.Position-content-center {
  font-size: 13px;
  color: #8d92a1;
  padding-right: 0;
  line-height: 28px;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vline {
  display: inline-block;
  width: 1px;
  height: 12px;
  vertical-align: middle;
  background: #e0e0e0;
  margin: 0 10px;
}
.Position-content-bottom {
  border-top: 1px solid #eef0f5;
  display: flex;
  margin-top: 8px;
  padding-top: 12px;
}
.Position-content-bottom > p {
  font-size: 14px;
  width: auto;
  padding-right: 0;
  border: 1px solid #f3f5fb;
  border-radius: 4px;
  line-height: normal;
}
.Position-content-bottom > p > img {
  width: 30px;
  height: 30px;
}
.Position-content-bottom-info {
  font-size: 13px;
  color: #8d92a1;
  display: flex;
  align-items: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.Position-content-bottom-info > .name {
  margin-left: 10px;
  margin-right: 20px;
  color: #61687c;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.Position-content-bottom-info > .type {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.Position-content-bottom-info > .level {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.position-btn {
  width: 200px;
  height: 40px;
  margin-left: 50%;
  transform: translateX(-50%);
  margin-top: 50px;
  margin-bottom: 250px;
  color: #fff;
  font-size: 16px;
  background-color: #55cbc4;
  border: none;
  cursor: pointer;
  outline: none;
}
.position-btn:hover {
  background-color: #5dd5cb;
}
</style>